package com.base.vistter.iframe.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.base.vistter.iframe.bean.SystemContextHolder;
import com.base.vistter.iframe.entity.InverterCollect;
import com.base.vistter.iframe.exception.IframeException;
import com.base.vistter.iframe.mapper.InverterCollectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional
@Slf4j
public class InverterCollectService extends BaseService<InverterCollectMapper, InverterCollect> {

    /**
     * 获取当前的登录人收藏的发电站ID集合
     */
    @Transactional(readOnly = true)
    public List<Integer> myCollectIds() throws IframeException {
        LambdaQueryWrapper<InverterCollect> lambdaQueryWrapper = new LambdaQueryWrapper<InverterCollect>();
        lambdaQueryWrapper.eq(InverterCollect::getSysUserId, SystemContextHolder.getSessionContext().getUserId());
        List<InverterCollect> list = super.selectList(lambdaQueryWrapper);
        return list.stream().map(InverterCollect::getInverterStationId).collect(Collectors.toList());
    }

}
